/*
 * @Author: ??????
 */

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int b=sc.nextInt();
        boolean a=((b%4==0)&&(b%100!=0))||(b%400==0);
        int y=sc.nextInt();
        System.out.println(y==2?(a?29:28):(y==1|y==3|y==5|y==7|y==8|y==10|y==12)?31:30);

}
}
